Initialize Packages

A cell with all the import

md"""
# Initialize Packages

A cell with all the import
"""
8.3 ms
begin
using PlutoUI, LinearAlgebra, Images, ImageShow
end
7.9 s
PlutoUI.TableOfContents()
4.0 ms

Read and Display Image

md"""
# Read and Display Image
"""
252 μs
url
"https://user-images.githubusercontent.com/6933510/107239146-dcc3fd00-6a28-11eb-8c7b-41aaf6618935.png"
url = "https://user-images.githubusercontent.com/6933510/107239146-dcc3fd00-6a28-11eb-8c7b-41aaf6618935.png"
# url ="https://www.google.com/url?sa=i&url=https%3A%2F%2Funsplash.com%2Fs%2Fphotos%2Fegyptian-cat&psig=AOvVaw1xYgdNItObx3eNC5OH7KFT&ust=1649752004968000&source=images&cd=vfe&ved=0CAoQjRxqFwoTCKjvyaTLi_cCFQAAAAAdAAAAABAD"
17.3 μs
philip_fname
"/tmp/jl_wNDcXXYnBU"
philip_fname = download(url)
324 ms
Enter cell code...
94.1 μs
philip
philip = load(philip_fname)
821 ms
Enter cell code...
94.4 μs

Simple Julia Function and Broadcasting

md"""
# Simple Julia Function and Broadcasting
"""
230 μs
double (generic function with 1 method)
function double(x)
return x*2
end
461 μs
4.0
double(2.0)
18.0 μs
a
3×3 Matrix{Int64}:
 1  2   4
 2  3   4
 8  9  24
a = [1 2 4
2 3 4
8 9 24]
33.0 μs
3×3 Matrix{Int64}:
  2   4   8
  4   6   8
 16  18  48
double.(a)
88.7 ms
3×3 Matrix{Int64}:
 1  2   4
 2  3   4
 8  9  24
a
15.2 μs
flatten (generic function with 1 method)
flatten(a)=a[1:1:length(a)] # Flattens a matrix column wise
480 μs
flatten(a)
20.1 μs
Enter cell code...
92.8 μs

Taking Camera Input

This will not work on the remote server

md"""
# Taking Camera Input

This will not work on the remote server
"""
307 μs
@bind image_data FilePicker([MIME("image/jpg"), MIME("image/png")])
247 ms

MethodError: no method matching getindex(::Nothing, ::String)

  1. top-level scope@Local: 1[inlined]
image_data["data"]|> IOBuffer
---
# @bind fname file_input()
15.4 μs
myface1
myface1=philip
17.8 μs

[
myface1 myface1[ : , end:-1:1]
myface1[end:-1:1, :] myface1[end:-1:1, end:-1:1]
]
297 ms
[philip philip[:, end:-1:1]]
64.5 ms
philip[1:2:end, 1:2:end]
506 μs

Inspecting your data

md"""
# Inspecting your data
"""
230 μs
size(philip)
18.1 μs
row_i, col_i = (1,1)
22.7 μs
philip[row_i, col_i]
20.9 μs
Slider(1:10)
19.7 μs
1
Slider(1:10, show_value=true)
7.3 ms

PlutoUI 1 PlutoUI2 1

PlutoUI3 1 PlutoUI4 1

begin
row_start, row_end = (1,100)
col_start, col_end = (1,100)
md"""
PlutoUI $(@bind row_start Slider(1:size(philip)[1], show_value=true))
PlutoUI2 $(@bind row_end Slider(1:size(philip)[1], show_value=true))
PlutoUI3 $(@bind col_start Slider(1:size(philip)[2], show_value=true))
PlutoUI4 $(@bind col_end Slider(1:size(philip)[2], show_value=true))
"""
end
58.4 ms
reduced_phil
reduced_phil = philip[row_start:row_end, col_start:col_end]
30.6 μs
save( "reduced_phil2.png", reduced_phil)
94.3 ms
1
row_start
17.0 μs
864
size(philip)[1]
20.4 μs

Julia: Array Data Structure

md"""
# Julia: Array Data Structure
"""
227 μs
[1, 20, "hello"]
19.5 ms
[RGB(1,0,0), RGB(0,1,0), RGB(0,0,1)]
29.3 μs
[RGB(1,0,0) RGB(0,1,0)
RGB(0,0,1) RGB(0.5, 0.5, 0.5)]
734 ms
[RGB(x,0,0) for x in 0:0.1:1]
90.3 ms
[RGB(i, j, 0) for i in 0:0.1:1, j in 0:0.1:1]
99.2 ms
[RGB(i, j, 0) for i in 0:0.1:1, j in 0:0.1:1]
87.7 ms
philip_head
philip_head = reduced_phil
18.4 μs
[philip_head reverse(philip_head, dims=2)
reverse(philip_head, dims=1) rot180(philip_head)]
153 ms
1
@bind number_reds Slider(1:100, show_value=true)
1.4 ms
[RGB(red_value / number_reds, 0, 0) for red_value in 0:number_reds]
65.5 ms

Utils

This contains all the utilities used in the pluto notebook. For pluto reactive working style , it is recommended to collect utilities at the end

md"""
# Utils

This contains all the utilities used in the pluto notebook. For pluto reactive working style , it is recommended to collect utilities at the end
"""
302 μs
camera_input (generic function with 1 method)
function camera_input(;max_size=150, default_url="https://i.imgur.com/SUmi94P.png")
"""
<span class="pl-image waiting-for-permission">
<style>
.pl-image.popped-out {
position: fixed;
top: 0;
right: 0;
z-index: 5;
}

.pl-image #video-container {
width: 250px;
}

.pl-image video {
border-radius: 1rem 1rem 0 0;
}
.pl-image.waiting-for-permission #video-container {
display: none;
}
.pl-image #prompt {
display: none;
}
.pl-image.waiting-for-permission #prompt {
width: 250px;
height: 200px;
display: grid;
place-items: center;
font-family: monospace;
font-weight: bold;
text-decoration: underline;
cursor: pointer;
border: 5px dashed rgba(0,0,0,.5);
}
1.7 ms
file_input (generic function with 1 method)
function file_input()
"""
<form>
<label for="fname">File Name</label>
<input type="file" id="fname" name="fname"><br><br>
</form>
"""|>HTML
end
464 μs
HTML()
18.7 μs